package cn.sunshine.controller;

import cn.sunshine.domain.Product;
import cn.sunshine.domain.Result;
import cn.sunshine.feign.ProductFeginClient;
import cn.sunshine.mapper.ProductMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ProductController {
    @Autowired
    private ProductFeginClient productFeginClient;
    @Autowired
    private ProductMapper productMapper;
    // @GetMapping("/product")
    /*@PostMapping("/product/add")
    public Result add(@RequestBody Product product){
        *//*Product product = new Product();
        product.setPrice(20L);
        product.setName("好的");
        product.setNumber(100L);*//*

        productMapper.add(product);
        //Product product1 = productMapper.findById(product.getId());
        //System.out.println(product1);
        Store store = Store.builder().productId(product.getId()).number(product.getNumber()).build();
        productFeginClient.add(store);
        return new Result();
    }*/

    @PostMapping("/product/add")
    public Result add(@RequestBody Product product){
        /*Product product = new Product();
        product.setPrice(20L);
        product.setName("好的");
        product.setNumber(100L);*/

        productMapper.add(product);
        Product product1 = productMapper.findById(product.getId());
        System.out.println(product1);
        // Store store = Store.builder().productId(product.getId()).number(product.getNumber()).build();

        return productFeginClient.add(product1);
    }
}
